"""
The MIT License (MIT)
Copyright © 2021 Walkline Wang (https://walkline.wang)
Gitee: https://gitee.com/walkline/micropython-video-stream
"""
from client1 import Client
from config import Config
from wifihandler import WifiHandler
from machine import I2C, Pin, reset
from drivers.ssd1306 import SSD1306_I2C


if __name__ == '__main__':
	i2c = I2C(0, scl=Pin(18), sda=Pin(19))
	slave_list = i2c.scan()

	if not slave_list:
		exit(0)

	if WifiHandler.STATION_CONNECTED == WifiHandler.set_sta_mode(Config.SSID, Config.PASSWORD):
			print('slave id: {}'.format(slave_list[0]))

			oled = SSD1306_I2C(128, 64, i2c)
			client = Client(oled)

			# client.start('192.168.0.25')
			client.start('192.168.137.1')
	else:
		# 600 秒后无法连接指定的 wifi 则重启
		reset()
